package edu.neusoft.springhtmldemo.controller;

import edu.neusoft.springhtmldemo.domain.LogManagement;
import edu.neusoft.springhtmldemo.service.LogManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.TimeZone;

@RestController
public class LogManagementController {
    @Autowired
    private LogManagementService service;

    @RequestMapping("/showLogManagement")
    public List<LogManagement> showLogManagement(){
        List<LogManagement> lists=service.showLogManagement();
//        for (LogManagement list : lists) {
//            System.out.println(list);
//        }
        return lists;
    }

    @RequestMapping("/selectLogManagement")
    public List<LogManagement> selectLogManagement(String maintainNum,String mantainBeginTime,String mantainEndTime,String maintainer){
        if(mantainBeginTime.length()>0){
            mantainBeginTime=mantainBeginTime.substring(0,10);
        }
        if(mantainEndTime.length()>0){
            mantainEndTime=mantainEndTime.substring(0,10);
        }
        return service.selectLogManagement(maintainNum,mantainBeginTime,mantainEndTime,maintainer);
    }

    @RequestMapping("/addLogManagement")
    public void addLogManagement(@Validated LogManagement management){
//        System.out.println(management);
        service.addLogManagement(management);
    }

    @RequestMapping("/updateUserLogManagement")
    public void updateUserLogManagement(LogManagement logManagement){
        service.updateUserLogManagement(logManagement);
    }

}
